﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DynaPrecision.LinearSystem
{
	public class IndexerBinder<T> : IMultiDimensionalArray<T>
	{

		private IMultiDimensionalArray<T> _underlyingArray;
		private int[] _indexBindedArray;
		private bool[] _isBindedArray;
		private int _totalBindCount
		{
			get
			{
				return _isBindedArray.Count(t => t);
			}
		}
		public IMultiDimensionalArray<T> UnderlyingArray
		{
			set
			{
				_underlyingArray = value;
				_indexBindedArray = new int[_underlyingArray.Dimension];
				_isBindedArray = new bool[_underlyingArray.Dimension];
			}
		}
		public void BindIndex(int dimension, int index)
		{
			_indexBindedArray[dimension] = index;
			_isBindedArray[dimension] = true;

		}
		public void UnbindIndex(int dimension)
		{
			_isBindedArray[dimension] = false;
		}

		#region IMultiDimensionalArray<T> Members

		public T this[params int[] index]
		{
			get
			{
				throw new NotImplementedException();
			}
			set
			{
				throw new NotImplementedException();
			}
		}

		public int GetLength(int DimensinNumber)
		{
			int i = 0, j = 0;
			for (; i < _underlyingArray.Dimension; i++)
			{
				if (!_isBindedArray[i])
				{
					j++;
				}
				if (j == DimensinNumber)
				{
					break;
				}
			}
			return _underlyingArray.GetLength(i);
		}

		public int Dimension
		{
			get { return _underlyingArray.Dimension - _totalBindCount; }
		}

		#endregion
	}
}
